package com.longteng.lesson.controller;

import com.google.common.collect.Maps;
import com.longteng.lesson.po.Department;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator
 * DATE : 2018/5/26
 * TIME : 21:38
 * PROJECT : java-lesson
 * PACKAGE : com.longteng.lesson
 *
 * @author <a href="mailto:taki@qq.com">Administrator</a>
 */
@Controller
@RequestMapping("/department")
public class BootstrapController {

    @RequestMapping("/")
    public String index(){
        return "bootstrap/layout";
    }

    @RequestMapping("/leftPage")
    public String leftPage(){
        return "bootstrap/layout";
    }

    @RequestMapping("/bootstrapPage")
    public String bootstrapPage(){
        return "bootstrap/departmentList";
    }
    //
    @RequestMapping("/getDepartment")
    public @ResponseBody Map getDepartment(int limit, int offset, String departmentName, String status)
    {
        List departments = new ArrayList<Department>();
        for (int i = 1; i <= 50; i++)
        {
            Department department = new Department();
            department.setId(i);
            department.setName("技术部"+i);
            department.setLevel(String.valueOf(i));
            department.setDesc("暂无描述信息");
            departments.add(department);
        }

        int total = departments.size();
        List list = departments.subList(offset,offset+limit);
        Map map = Maps.newHashMap();
        map.put("total",total);
        map.put("rows",list);

        return map;
    }


    @RequestMapping("/editDepartment")
    public ModelAndView editDepartment(Department department){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("/bootstrap/addDepartmentPage");
        modelAndView.addObject("department",department);
        return modelAndView;
    }

    @RequestMapping("/deleteDepartment")
    public String deleteDepartment(){
        return null;
    }


    @RequestMapping("/addDepartmentPage")
    public ModelAndView addDepartmentPage(){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("/bootstrap/addDepartmentPage");
        return modelAndView;
    }

    @RequestMapping("/matrixMain")
    public String matrixMain(){
        return "matrixMain";
    }
    @RequestMapping("/matrixTop")
    public String matrixTop(){
        return "matrixTop";
    }
}
